<template>
	<view style="padding-bottom: 200rpx;">
		<view style="padding: 20rpx;background-color: white;height: 100rpx;width:95%;margin:20rpx auto;">
			<view style="float: left;height: 60rpx;line-height: 60rpx;">详细地址</view>
			<view style="float: left;height: 60rpx;height: 60rpx;margin-left: 20rpx;">
				<input type="text" style="height: 60rpx;height: 60rpx;" v-model="address" placeholder="请输入详细地址">
			</view>
		</view>
		<view style="padding: 20rpx;background-color: white;height: 280rpx;width:95%;margin:20rpx auto;">
			<view style="height: 60rpx;line-height: 60rpx;">个人简介</view>
			<view style="margin-left: 20rpx;">
				<textarea name="" v-model="introduction" style="height: 200rpx;" placeholder="请输入个人简介" id="" cols="30" rows="10"></textarea>
			</view>
		</view>
		<view style="padding: 20rpx;background-color: white;height: 100rpx;width:95%;margin:20rpx auto;">
			<view style="float: left;height: 60rpx;line-height: 60rpx;">从业年份</view>
			<view style="float: left;height: 60rpx;height: 60rpx;margin-left: 20rpx;">
				<input type="number" style="height: 60rpx;height: 60rpx;" v-model="work_year" placeholder="请输入从业年份">
			</view>
		</view>
		<view style="padding: 20rpx;background-color: white;height: 100rpx;width:95%;margin:20rpx auto;">
			<view style="float: left;height: 60rpx;line-height: 60rpx;">身份证号</view>
			<view style="float: left;height: 60rpx;height: 60rpx;margin-left: 20rpx;">
				<input type="text" style="height: 60rpx;height: 60rpx;" v-model="id_card" placeholder="请输入身份证号">
			</view>
		</view>
		<view style="padding: 20rpx;background-color: white;width:95%;margin:20rpx auto;">
			<view style="">身份证照片（请分别上传身份证人像面、身份证国徽面、手持身份证照片）</view>
			<view style="margin-left: 20rpx;display: flex;">
				<view style="width: 150rpx;height: 150rpx;margin-left: 20rpx;" v-for="item in id_card_img">
					<image :src="item" style="width: 150rpx;height: 150rpx;" mode=""></image>
				</view>
				<view style="text-align: center;width: 150rpx;height: 150rpx;background-color: #dcdcdc;line-height: 150rpx;font-size: 40rpx;margin-left: 20rpx;" @click="chooseImage('id_card_img')" v-if="id_card_img.length < 3">
					+
				</view>
			</view>
		</view>
		
		<view style="padding: 20rpx;background-color: white;width:95%;margin:20rpx auto;">
			<view style="">资格证书</view>
			<view style="margin-left: 20rpx;display: flex;">
				<view style="width: 150rpx;height: 150rpx;margin-left: 20rpx;" v-for="item in qualification_img">
					<image :src="item" style="width: 150rpx;height: 150rpx;" mode=""></image>
				</view>
				<view style="text-align: center;width: 150rpx;height: 150rpx;background-color: #dcdcdc;line-height: 150rpx;font-size: 40rpx;margin-left: 20rpx;" @click="chooseImage('qualification_img')">
					+
				</view>
			</view>
		</view>
		
		
		<view style="padding: 20rpx;background-color: white;width:95%;margin:20rpx auto;">
			<view style="">工作形象照</view>
			<view style="margin-left: 20rpx;display: flex;">
				<view style="width: 150rpx;height: 150rpx;margin-left: 20rpx;" v-for="item in work_img">
					<image :src="item" style="width: 150rpx;height: 150rpx;" mode=""></image>
				</view>
				<view style="text-align: center;width: 150rpx;height: 150rpx;background-color: #dcdcdc;line-height: 150rpx;font-size: 40rpx;margin-left: 20rpx;" @click="chooseImage('work_img')">
					+
				</view>
			</view>
		</view>
		
		<view style="padding: 20rpx;background-color: white;width:95%;margin:20rpx auto;">
			<view style="">个人生活照</view>
			<view style="margin-left: 20rpx;display: flex;">
				<view style="width: 150rpx;height: 150rpx;margin-left: 20rpx;" v-for="item in life_img">
					<image :src="item" style="width: 150rpx;height: 150rpx;" mode=""></image>
				</view>
				<view style="text-align: center;width: 150rpx;height: 150rpx;background-color: #dcdcdc;line-height: 150rpx;font-size: 40rpx;margin-left: 20rpx;" @click="chooseImage('life_img')">
					+
				</view>
			</view>
		</view>
		
		<view style="padding: 20rpx;background-color: white;height: 100rpx;width:95%;margin:20rpx auto;">
			<view style="float: left;height: 60rpx;line-height: 60rpx;">接单时间</view>
			<view style="float: left;height: 60rpx;height: 60rpx;margin-left: 20rpx;">
				<picker mode="time" @change="listen_start_time">
					<view style="height: 60rpx;height: 60rpx;line-height: 60rpx;">{{start_time}}</view>
				</picker>
			</view>
			<view style="float: left;height: 60rpx;height: 60rpx;line-height: 60rpx;margin-left: 20rpx;margin-right: 20rpx;"> ~ </view>
			<view style="float: left;height: 60rpx;height: 60rpx;margin-left: 20rpx;">
				<picker mode="time" @change="listen_end_time">
					<view style="height: 60rpx;height: 60rpx;line-height: 60rpx;">{{end_time}}</view>
				</picker>
			</view>
		</view>
		
		<view style="background-color: orange;color: white;width: 50%;text-align: center;margin: 40rpx auto;height: 70rpx;line-height: 70rpx;" @click="submit">
			提交
		</view>
		
	</view>
</template>

<script>
	import {
		mapState,
		mapActions,
		mapMutations
	} from "vuex"
	export default {
		data() {
			return {
				address:'',
				introduction:'', //个人简介
				work_year:'',//从业年份
				id_card:'',//身份证号
				id_card_img:[],//身份证图片
				qualification_img:[],//资格证书图片
				work_img:[],//工作形象照
				life_img:[],//个人生活照
				start_time:'00:00',
				end_time:'23:99'
			}
		},
		onLoad() {
			this.getCoach()
		},
		computed: mapState({
			coachInfo: state => state.user.coachInfo,
		}),
		methods: {
			...mapActions(['getConfigInfo', 'getUserInfo', 'getMineInfo', 'getCoachInfo','submitCoach','updateCommonOptions']),
			async submit(){
				
				if(this.address == '' || this.introduction == '' || this.work_year == '' || this.id_card == ''){
					uni.showToast({
						title:'请输入完整信息',
						icon:"error"
					})
					return
				}
				
				
				uni.request({
				    url:'https://tongchengkangyue.9085.com.cn/massage/admin/submitCoach',
				    data: {
				        id: this.coachInfo.id,
						address:this.address,
						work_time:this.work_year,
						text:this.introduction,
						start_time:this.start_time,
						end_time:this.end_time,
						id_code:this.id_card
				    },
				    header: {
				        'custom-header': 'hello' //自定义请求头信息
				    },
				    success: (res) => {
				        console.log(res.data);
						if(res.data.code == 200){
							uni.showToast({
								title:res.data.data
							})
						}
				    }
				});

			},
			async getCoach(){
				await this.getCoachInfo()
				// let {
				// 	coach_status,
				// 	is_admin = 0,
				// 	is_fx = 0
				// } = this.mineInfo
				console.log(this.coachInfo,999)
				this.address = this.coachInfo.address
				this.work_year = this.coachInfo.work_time
				this.introduction = this.coachInfo.text
				if(this.coachInfo.start_time != ''){
					this.start_time = this.coachInfo.start_time
				}
				if(this.coachInfo.end_time != ''){
					this.end_time = this.coachInfo.end_time
				}
				
				this.id_card = this.coachInfo.id_code
			},
			listen_start_time(e){
				this.start_time = e.detail.value
			},
			listen_end_time(e){
				this.end_time = e.detail.value
			},
			chooseImage(type){
				let that = this
				uni.chooseImage({
					count: 1,
					sizeType: ['original', 'compressed'], //可以指定是原图还是压缩图，默认二者都有
					sourceType: ['album'], //从相册选择
					success: function (res) {
						if(type == 'id_card_img'){
							that.id_card_img.push(res.tempFilePaths[0])
						}
						if(type == 'qualification_img'){
							that.qualification_img.push(res.tempFilePaths[0])
						}
						if(type == 'work_img'){
							that.work_img.push(res.tempFilePaths[0])
						}
						if(type == 'life_img'){
							that.life_img.push(res.tempFilePaths[0])
						}
					}
				});

			}
		}
	}
</script>

<style>

</style>
